#include "Node.h"
#include <iostream>
#include <stdio.h>
Node::Node()
{
	this -> number = 0;
	this -> next = NULL;
	this -> prev = NULL;
}
Node::Node(int x)
{
	this -> number = x;
	this -> next = NULL;
	this -> prev = NULL;
}
int Node::getNumber(void) const
{
	return this -> number;
}
Node* Node::getNext(void) const
{
	return this -> next;
}
Node* Node::getPrev(void) const
{
	return this -> prev;
}
void Node::setNext(Node *p)
{
	this -> next = p;
}
void Node::setPrev(Node *p)
{
	this -> prev = p;
}
std::istream& operator >> (std::istream &in, Node &N)
{
	in >> N.number;
	return in;
}
List::List()
{
	first = last = NULL;
}
void List::operator + (int n)
{
	Node *tmp = new Node(n);
	if (this -> first == NULL)
	{
		this -> first = tmp;
		this -> last = tmp;
	}
	else
	{
		tmp -> setPrev(this -> last);
		this -> last -> setNext(tmp);
		this -> last = tmp;
	}
}
void List::operator + (const Node &N)
{
	Node *tmp = new Node(N.getNumber());
	if (this -> first == NULL)
	{
		this -> first = tmp;
		this -> last = tmp;
	}
	else
	{
		tmp -> setPrev(this -> last);
		this -> last -> setNext(tmp);
		this -> last = tmp;
	}
}
void List::Print(void) const
{
	Node *tmp = this -> first;
	for (; tmp != NULL; tmp = tmp -> getNext())
		printf("%d ", tmp -> getNumber());
}
bool List::operator == (const List &L)
{
	Node 	*tmp1 = this -> first, *tmp2 = L.first;
	bool ok = true;
	while (tmp1 != NULL && tmp2 != NULL)
	{
		if (tmp1 -> getNumber() != tmp2 -> getNumber())
		{	
			ok = false;
			break;
		}	
		tmp1 = tmp1 -> getNext();
		tmp2 = tmp2 -> getNext();
	}
	return ok;
}
bool List::operator == (const List *L)
{
	Node 	*tmp1 = this -> first, *tmp2 = L -> first;
	bool ok = true;
	while (tmp1 != NULL && tmp2 != NULL)
	{
		if (tmp1 -> getNumber() != tmp2 -> getNumber())
		{	
			ok = false;
			break;
		}	
		tmp1 = tmp1 -> getNext();
		tmp2 = tmp2 -> getNext();
	}
	return ok;
}
bool List::operator != (const List &L)
{
	Node 	*tmp1 = this -> first, *tmp2 = L.first;
	bool ok = true;
	while (tmp1 != NULL && tmp2 != NULL)
	{
		if (tmp1 -> getNumber() != tmp2 -> getNumber())
		{	
			ok = false;
			break;
		}	
		tmp1 = tmp1 -> getNext();
		tmp2 = tmp2 -> getNext();
	}
	return !ok;
}
bool List::operator != (const List *L)
{
	Node 	*tmp1 = this -> first, *tmp2 = L -> first;
	bool ok = true;
	while (tmp1 != NULL && tmp2 != NULL)
	{
		if (tmp1 -> getNumber() != tmp2 -> getNumber())
		{	
			ok = false;
			break;
		}	
		tmp1 = tmp1 -> getNext();
		tmp2 = tmp2 -> getNext();
	}
	return !ok;
}
using namespace std;
int main()
{
	int i = 1;
	List L1, L2;
	Node N;
	while (i <= 5)
	{	
		cin >> N;
		L1 + N;
		++i;
	}
	i = 1;
	while (i <= 5)
	{	
		cin >> N;
		L2 + N;
		++i;
	}
	L1.Print();
	printf("\n");
	L2.Print();
	printf("\n");
	if (L1 != &L2)
		printf("Yes.");
	else
		printf("No.");
	return 0;
}